package com.liziyi0914.morearmor.armor;

import com.liziyi0914.morearmor.MoreArmorMod;
import lombok.Getter;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class BaseArmor extends ArmorItem {
    @Getter
    private final Item item;

    public BaseArmor(Item item, ArmorMaterial material, EquipmentSlot slot) {
        super(material, slot, new Item.Settings().group(MoreArmorMod.GROUP));
        this.item = item;
    }
    @Override
    public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
        tooltip.add(new TranslatableText(item.getTranslationKey()));
    }

    @Override
    public String getTranslationKey() {
        final String key = super.getTranslationKey();
        if (I18n.hasTranslation(key)) {
            return key;
        }
        return "item.more_armor.base_" + getSlotName(getSlotType());
    }

    @Override
    public Text getName() {
        return new TranslatableText(getTranslationKey(), item.getName().getString());
    }

    @Override
    public Text getName(ItemStack stack) {
        return new TranslatableText(getTranslationKey(stack), item.getName().getString());
    }

    private static String getSlotName(EquipmentSlot slot){
        switch (slot) {
            case FEET -> {
                return "boots";
            }
            case HEAD -> {
                return "helmet";
            }
            case LEGS -> {
                return "leggings";
            }
            case CHEST -> {
                return "chestplate";
            }
        }
        return slot.getName();
    }
}